﻿using System;
using System.Collections.Generic;
using System.ComponentModel;
using System.Data;
using System.Drawing;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
using System.Windows.Forms;

namespace Tools.Dialog
{
    public partial class EnterMac : Form
    {
        public string MacAddr { get { return this.textBoxMAc.Text.Trim(); } }

        public EnterMac(Point point)//传递出现此窗口的位置
        {
            InitializeComponent();
            this.Location = point;
        }

        private void textBoxMAC_KeyPress(object sender, KeyPressEventArgs e)
        {
            //只能输入16进制数字和回车符号'\r'或者'\n'，MAC地址中的字符只能位0-9,A~F
            if (e.KeyChar == '\n' || e.KeyChar == '\r')
            {
                e.Handled = true;
                if (this.textBoxMAc.Text.Trim().Length != 12)
                {
                    this.textBoxMAc.Clear();
                    this.textBoxMAc.Focus();
                }
                else
                {
                    //this.DialogResult = DialogResult.OK;
                    this.DialogResult = DialogResult.OK;
                    this.Close();
                }
            }
            else if ((e.KeyChar >= 'a' && e.KeyChar <= 'f')
                || (e.KeyChar >= 'A' && e.KeyChar <= 'F')
                || (e.KeyChar >= '0' && e.KeyChar <= '9')
                || (e.KeyChar == 8))
            {
                //判断是否位16进制字符，将小写全部转为大写
                e.Handled = false;
            }
            else
            {
                MessageBox.Show("只能输入数字和A-F");
                this.textBoxMAc.Clear();
                this.textBoxMAc.Focus();
                e.Handled = true;
            }
        }
    }
}
